#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
string s;
int n,k;
struct node{
	int sz,num;
}a[100005];
int num[100005];

bool cmp(node x,node y){
	if(x.num==y.num)return x.sz<y.sz;
	else return x.num>y.num;
}

void read(){
	int cnt=1,tmp=0;
	char c;
	for(int i=0;i<s.size();i++){
		c=s[i];
		if(c==','){
			num[cnt++]=tmp;
			tmp=0;
		}else if((c-'0')>=0 && (c-'0')<=9){
			tmp=tmp*10+c-'0';
		}
	}
	num[cnt]=tmp;
	n=cnt;
}

int main(){
	
	while(cin>>s>>k){
		for(int i=1;i<=100005;i++){
			a[i].sz=0;
			a[i].num=0;
			num[i]=0;
		}
		read();
		int tmp,cnt=0;
		for(int i=1;i<=n;i++){
			tmp=num[i];
			if(a[tmp].sz==0){
				a[tmp].sz=tmp;
				cnt++;
			}
			a[tmp].num++;	
		}
		
		sort(a+1,a+1+cnt,cmp);
		for(int i=1;i<=k;i++){
			if(i==k){
				cout<<a[i].sz<<endl;
				break;
			}
			cout<<a[i].sz<<",";
		}	
	}
	
	return 0;
}

